package view.parameterpanels;

import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;
import view.CenterTabbedPane.EBenchmarkTab;
import view.EBenchmarkPanel;

//#Neu
/**
 * The view class {@code ScalingResultPanel} draws a panel that shows the
 * scaling results and lets the user choose one of the results that is to be 
 * visualized by a graph.
 * @author Sebastian Perlwitz
 *
 */
public class ScalingResultPanel extends EBenchmarkPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * The title that gives the user a description of the panel.
	 */
	private JLabel title;
	
	/**
	 * The most important part of a {@code ParameterPanel}. On this panel the
	 * radio button and all important parameter information are drawn.
	 */
	private JPanel paramPanel;
	
	/**
	 * A list that holds all check boxes.
	 */
	private ArrayList<JCheckBox> listcbs;
    	
	/**
	 * To create a new {@code ScalingResultPanel}.
	 * @param logoPath a path to an optional logo. If passed {@code null} a
	 * standard logo is used.
	 * @param tab the type of input parameters that is displayed on the panel.
	 */
	public ScalingResultPanel(
			String logoPath,
			EBenchmarkTab tab,
			String panelTitle) {
		super(logoPath, tab);
		this.setName(panelTitle);
		
		listcbs = new ArrayList<JCheckBox>();
		init();
	}
	
	/**
	 * To initiate the panel and add components.
	 */
	private void init() {
		
		title = new JLabel("Ergebnisdarstellung");
		
		paramPanel = new JPanel();
		paramPanel.setLayout(new MigLayout());
		
		this.setLayout(new MigLayout());
		this.add(title, "wrap");		
		this.add(paramPanel);
		this.add(logo, "aligny top");
	}
	
	/**
	 * To add a parameter set to this panel.
	 * @param paramInfo the parameters' information:<br>
     * paramInfo[0] = parameter's name<br>
     * paramInfo[1] = parameter's abbreviation<br>
     * paramInfo[2] = parameter's unit<br>
     * paramInfo[3] = parameter's initial value.
     * @param borderTitle the parameters' description.
     */
	public void addParameterSet(
			List<String[]> paramInfo,
			String borderTitle,
			String scalingID) {
		
		JPanel parameterPanel = new JPanel(new MigLayout("wrap 5"));
		parameterPanel.setBorder(BorderFactory
                .createTitledBorder(borderTitle));
		
		// Create a new CheckBox and add it to the list of check boxes and 
		// the parameter panel.
		JCheckBox cb = new JCheckBox();
		cb.putClientProperty(cb, scalingID);
		listcbs.add(cb);
		parameterPanel.add(cb);
		
        // Iterate through every parameter of this set.
        for(String[] parameter : paramInfo) {
            parameterPanel.add(new JLabel(parameter[0]));            
            parameterPanel.add(new JLabel(parameter[1]));
            parameterPanel.add(new JLabel(parameter[2]));
            parameterPanel.add(new JLabel(parameter[3]));
        }
        paramPanel.add(parameterPanel, "wrap");
        paramPanel.revalidate();
	}
	
	@Override
	public void update() {
		// TODO Auto-generated method stub
	}
	
	/**
	 * To get the parameter panel from this panel.
	 * @return The parameter panel.
	 */
	public JPanel getParameterPanel() {
		return paramPanel;
	}
	
	/**
	 * To deselect all JCheckBoxes of this view.
	 */
	public void deselectAllCheckBoxes() {
		for(JCheckBox cb : listcbs) {
			cb.setSelected(false);
		}
	}
	
	/**
	 * To get the scaling IDs of every selected check box.
	 * @return The scaling IDs.
	 */
	public ArrayList<String> getSelectedCheckBoxIDs() {
		ArrayList<String> listScalingIDs = new ArrayList<String>();
		
		for(JCheckBox cb : listcbs) {
			if(cb.isSelected()) {
				listScalingIDs.add((String) cb.getClientProperty(cb));
			}
		}
		return listScalingIDs;
	}
    
}
